<template>
	<view>
		<u-navbar :is-back="false" title="　" :border-bottom="false">
		</u-navbar>
		<view class="u-flex user-box u-p-l-30 u-p-r-20 u-p-b-30">
			<view class="u-m-r-10">
				<u-avatar :src="pic" size="140"></u-avatar>
			</view>
			<view class="u-flex-1">
				<view class="u-font-18 u-p-b-20">{{userInfo.realName||'admin'}}</view>
				<view class="u-font-14 u-tips-color">电话:{{userInfo.mobile||'xxxxxxxxxxx'}}</view>
			</view>
		</view>

		<view class="u-m-t-20">
			<u-cell-group>
				<u-cell-item icon="coupon" title="个人详情" @click="goMeDetail"></u-cell-item>
			</u-cell-group>
		</view>

		<view class="u-m-t-20">
			<u-cell-group>
				<u-cell-item icon="star" title="我的服务" @click="goService"></u-cell-item>
				<u-cell-item icon="bookmark" title="考勤打卡" @click="goAttendance"></u-cell-item>
			</u-cell-group>
		</view>

		<view class="u-m-t-20">
			<u-cell-group>
				<u-cell-item icon="setting" title="退出" @click="logout"></u-cell-item>
			</u-cell-group>
		</view>
		<tabbar-footer></tabbar-footer>
	</view>
</template>

<script>
	import {
		getUserInfo
	} from '@/api/me/me.js'
	import tabbarFooter from '../tabbar/tabbar-footer.vue'
	export default {
		data() {
			return {
				pic: '../../static/avatar@2x.png',
				show: true,
				userInfo: {}
			}
		},
		components: {
			tabbarFooter
		},
		onLoad() {
			this.isLogin()
		},
		onShow() {
			this.getUser()
		},
		methods: {
			// 跳转到我的详情
			goMeDetail() {
				uni.navigateTo({
					url: '/pages/me/meDetail'
				})
			},
			// 跳转到我的服务
			goService() {
				uni.navigateTo({
					url: '/pages/service/service'
				})
			},
			// 跳转到考勤打卡
			goAttendance() {
				uni.navigateTo({
					url: '/pages/attendance/attendance'
				})
			},
			// 获取用户信息
			getUser() {
				getUserInfo().then(res => {
					console.log(res)
					this.userInfo = res.data
					uni.setStorageSync('userInfo', res.data)
				})
			},
			// 判断路由是否登陆
			isLogin() {
				let token = uni.getStorageSync('token')
				if (uni.getStorageSync('token') === '') {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}
			},
			// 退出登录
			logout() {
				console.log('退出登录')
				uni.clearStorageSync()
				uni.navigateTo({
					url: '/pages/login/login'
				})
			},
			changePopupShow() {
				this.$refs.popup.show = true
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #ededed;
	}

	.camera {
		width: 54px;
		height: 44px;

		&:active {
			background-color: #ededed;
		}
	}

	.user-box {
		background-color: #fff;
	}
</style>